﻿#ifndef __SS_CFG_HELP_H__
#define __SS_CFG_HELP_H__
#include "./ssStrfunc.h"

namespace StarSeeker
{

	class ssCfgHelper
	{
	public:
		//获取字段(数组)
		static void FieldArr(std::vector<std::string>& out, const std::string& str, char delimiter = ':')
		{
			out.clear();
			if (str.empty())
				return;
			StringSplit(str, delimiter, out);
		}
		//获取字段(int数组)
		static void FieldIntArr(std::vector<int>& out, const std::string& str, char delimiter = ':')
		{
			out.clear();
			if (str.empty())
				return;
			std::vector<std::string> strArr;
			StringSplit(str, delimiter, strArr);
			if (strArr.size() > 0)
			{
				for (size_t i = 0; i < strArr.size(); i++)
				{
					out.push_back(Str2Int32(strArr[i].c_str()));
				}
			}
		}
		//获取字段(float数组)
		static void FieldFloatArr(std::vector<float>& out, const std::string& str, char delimiter = ':')
		{
			out.clear();
			if (str.empty())
				return;
			std::vector<std::string> strArr;
			StringSplit(str, delimiter, strArr);
			if (strArr.size() > 0)
			{
				for (size_t i = 0; i < strArr.size(); i++)
				{
					out.push_back(Str2Float(strArr[i].c_str()));
				}
			}
		}
		//获取字段(二维数组)
		static void FieldTDArr(std::vector<std::vector<std::string> >& out, const std::string& str)
		{
			out.clear();
			if (str.empty())
				return;
			StringSplit(str, '|', ':', out);
		}
		//获取字段(int二维数组)
		static void FieldIntTDArr(std::vector<std::vector<int> >& out, const std::string& str)
		{
			out.clear();
			if (str.empty())
				return;
			std::vector<std::vector<std::string> > strArr;
			StringSplit(str, '|', ':', strArr);
			if (strArr.size() > 0)
			{
				std::vector<int> v;
				for (size_t i = 0; i < strArr.size(); i++)
				{
					std::vector<std::string>& arr = strArr[i];
					v.clear();
					for (size_t j = 0; j < arr.size(); j++)
					{
						v.push_back(Str2Int32(arr[j].c_str()));
					}
					out.push_back(v);
				}
			}
		}
		//获取字段(float二维数组)
		static void FieldFloatTDArr(std::vector<std::vector<float> >& out, const std::string& str)
		{
			out.clear();
			if (str.empty())
				return;
			std::vector<std::vector<std::string> > strArr;
			StringSplit(str, '|', ':', strArr);
			if (strArr.size() > 0)
			{
				std::vector<float> v;
				for (size_t i = 0; i < strArr.size(); i++)
				{
					std::vector<std::string>& arr = strArr[i];
					v.clear();
					for (size_t j = 0; j < arr.size(); j++)
					{
						v.push_back(Str2Float(arr[j].c_str()));
					}
					out.push_back(v);
				}
			}
		}
	};

}
#endif
